package com.focus.xyz.union.pages.frontend;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BasePage;
import com.focus.xyz.union.pages.frontend.tables.ProdInfoTable;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/4/20.
 */
public class ProdDetailPage extends BasePage {
    private Action action;
    private WebDriver driver;
    private static final String url = "http://union.xyz.cn/unionProduct/prodDetail";

    @FindBy(xpath = "//*[@id=\"dev_form\"]/div[2]/div[2]/table/tbody/tr[8]/td/button")
    private WebElement tbBtn;

    public ProdInfoTable prodInfoTable;
    @FindBy(xpath = "//ul[@class='tags-cal']/li")
    private List<WebElement> list;


    @FindBy(xpath = "//button[@title='立即投保']")
    private List<WebElement> tbBtnList;


    public ProdDetailPage(WebDriver driver,Action action){
        super(driver,action);
        this.action = action;
        this.driver = driver;
        PageFactory.initElements(driver,this);
        switchTo(url);
    }

    public void clickTbBtn() throws Exception{
        action.waitForElementPresent(By.xpath("//*[@id=\"dev_form\"]/div[2]/div[2]/table/tbody/tr[8]/td/button"));
        action.click(tbBtn);
    }

    public void clickTbBtnChrome() throws Exception{
        action.waitForElementPresent(By.xpath("//button[@title='立即投保']"));
        if(tbBtnList!=null&&tbBtnList.size()>0){
            action.click(tbBtnList.get(0));
        }
    }

}
